﻿using Microsoft.Win32;
using MS.Win32;
using System;
using System.ComponentModel;
using System.Configuration.Install;
using System.Runtime.InteropServices;

namespace ThinkPadDockHelper
{
    [RunInstaller(true)]
    public partial class TPDHInstaller : System.Configuration.Install.Installer
    {
        public TPDHInstaller()
        {
            InitializeComponent();
        }

        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {
            uint rc = 0;

            // Get the active power scheme
            Guid activePolicyGuid = Guid.Empty;
            rc = PowerUtil.PowerGetActiveScheme(ref activePolicyGuid);

            // Read the lid close action value index
            var acValueIndex = default(uint);
            rc = PowerUtil.PowerReadACValueIndex(ref activePolicyGuid, ref acValueIndex);

            var dcValueIndex = default(uint);
            rc = PowerUtil.PowerReadDCValueIndex(ref activePolicyGuid, ref dcValueIndex);

            // We will use the lid close action value index at install time
            // as the initial undocked state index.
            RegistryUtil.SetUndockedLidCloseActionACValueIndex(acValueIndex);
            RegistryUtil.SetUndockedLidCloseActionDCValueIndex(dcValueIndex);
        }
    }
}
